<?php


namespace App\HttpController\Admin;
use App\Repositories\Services\Admin;
use EasySwoole\Template\Render;


class Index extends Sys
{

   public function index(){
       $this->show('admin/index/index',['url'=>'/Admin/Index/console']);
   }

   public function console(){


       $data['total'] = rand(1000,9999);
       $data['todaytotal'] = rand(100,999);
       $dates = [];
       $usersDatas = [];
       for($i=1;$i<=7;$i++){
           $dates[] = date("Ymd",strtotime("-{$i} day"));
           $usersDatas[] = rand(100,999);
       }
       $data['date'] = implode(',',$dates);
       $data['usersDatas'] = implode(',',$usersDatas);

       $this->show('admin/index/console',$data);
   }

    public function login(){
        $this->show('admin/index/login',[]);
    }

    public function logout(){
       Admin::getInstance()->logout();
       $this->response()->redirect('/Admin/Index/login');
    }

    public function login_ajax(){
       $params = $this->request()->getRequestParam();
       list($status,$msg) = Admin::getInstance()->login($params['account'],$params['password'],$params['code'],$this->_clientIp);
       sleep(1);
       if($status){
           $this->ajaxSuccess(['adminId'=>$status],$msg);
       }else{
           $this->ajaxError(0,$msg);
       }
    }
    function reload(){
        Render::getInstance()->restartWorker();
        $this->response()->write(1);
    }
}